//
//  BFCircleTProgressLayer.swift
//  CALayerDemo
//
//  Created by HJQ on 2018/7/14.
//  Copyright © 2018年 HJQ. All rights reserved.
//

import UIKit

// MARK: - 有占位圆的圆环
class BFCircleTProgressLayer: BFBaseProgressLayer {

    override func draw(in ctx: CGContext) {

        // 获取到半径
        let radius = self.frame.width * 0.45
        let center = CGPoint.init(x: self.frame.width * 0.5, y: self.frame.height * 0.5)

        // 绘制灰色的占位圆环
        ctx.setStrokeColor(UIColor.gray.withAlphaComponent(0.8).cgColor)
        ctx.setLineWidth(radius * 0.07)
        // 在矩形内画圆
        ctx.addEllipse(in: CGRect.init(x: self.frame.width * 0.05, y: self.frame.height * 0.05, width: self.frame.width * 0.9, height: self.frame.height * 0.9))
        ctx.strokePath()

        // 设置画笔的颜色
        ctx.setStrokeColor(UIColor.cyan.cgColor)
        ctx.setLineWidth(radius * 0.08)
        // 设置端点的形状
        ctx.setLineCap(CGLineCap.round)

        let startAngle = -(CGFloat.pi * 0.5)
        let endAngle = CGFloat(self.number) * CGFloat.pi * 2.0 - CGFloat.pi * 0.5
        // clockwise 顺逆时针
        ctx.addArc(center: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: false)
        ctx.strokePath()
    }

}
